package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.EnlinkProductAreaServerDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.enlink.EnlinkProductAreaServer;

@Repository("enLinkProductAreaServerDAO")
public class EnlinkProductAreaServerDAOImpl extends
		SuperDAO<EnlinkProductAreaServer> implements EnlinkProductAreaServerDAO {

	@Override
	public Pagination<EnlinkProductAreaServer> queryPaginationList(
			EnlinkProductAreaServer enLinkAreaServerInfo) {
		Pagination<EnlinkProductAreaServer> paginationList = null;
		Integer rowCount = queryRowCount(enLinkAreaServerInfo);

		enLinkAreaServerInfo.calculate();
		List<EnlinkProductAreaServer> list = queryGoodsInfoList(enLinkAreaServerInfo);
		paginationList = this.queryPagination(rowCount, list,
				enLinkAreaServerInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(EnlinkProductAreaServer enLinkGoodsInfo) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.EnlinkProductAreaServerMapper.queryRowCount",
				enLinkGoodsInfo);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<EnlinkProductAreaServer> queryGoodsInfoList(
			EnlinkProductAreaServer enLinkGoodsInfo) {
		List<EnlinkProductAreaServer> list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.EnlinkProductAreaServerMapper.queryEnlinkAreaServerInfoList",
						enLinkGoodsInfo);
		return list;
	}

	@Override
	public void insert(EnlinkProductAreaServer areaServer) {
		this.getSqlSession().insert(
				"mybatis.xml.EnlinkProductAreaServerMapper.insert", areaServer);
	}

	@Override
	public EnlinkProductAreaServer queryAreaServer(
			EnlinkProductAreaServer enLinkAreaServerInfo) {
		EnlinkProductAreaServer as = this.getSqlSession().selectOne(
				"mybatis.xml.EnlinkProductAreaServerMapper.queryAreaServer",
				enLinkAreaServerInfo);
		return as;
	}

	@Override
	public List<EnlinkProductAreaServer> queryByProductId(String productId) {
		List<EnlinkProductAreaServer> list = this.getSqlSession().selectList(
				"mybatis.xml.EnlinkProductAreaServerMapper.queryByProductId",
				productId);
		return list;
	}

	@Override
	public List<String> queryAreaNameByProductId(String productId) {
		List<String> list = this
				.getSqlSession()
				.selectList(
						"mybatis.xml.EnlinkProductAreaServerMapper.queryAreaNameByProductId",
						productId);
		return list;
	}

	@Override
	public void update(EnlinkProductAreaServer areaServer) {
		this.getSqlSession().insert(
				"mybatis.xml.EnlinkProductAreaServerMapper.update", areaServer);
	}

	@Override
	public void delete() {
		this.getSqlSession().delete("mybatis.xml.EnlinkProductAreaServerMapper.delete");
	}

}
